@extends('home.layout.base')
<link rel="stylesheet" href="{{URL::asset('./css/hrmy/order.css')}}">
@section('content')
<div class="mainHrContent" id="hrOrder">
    <div class="storelistTitle">
        <span class="storelistTitle_left">
            <span>
                <img src="{{URL::asset('./img/icon/home.png')}}">
            </span>
            <span><a href="{{route('home.index.index') }}">首页</a> >
                <a href="{{route('home.hrmy.hrIndex') }}">用户中心</a>
                > 订单管理中心
            </span>
        </span>
        <span class="storelistTitle_right">
            <span>找不到合适的供应商？发个需求试试？</span>
            <button @click=" window.location.href = '{{ route('home.demand.demandAdd') }}'">免费发布需求</button>
        </span>
    </div>
    <div class="hrContent">
        @include('home.hrmy.menu')
        <div class="basicInfo" id="hrOrders">
            <div class="basicInfo_title">
                <span></span>
                订单管理中心
            </div>
            <div class="orderMain">
                <div class="orderMain_header">
                    <span>订单状态：</span>
                    <button :class="{active:state_type==0}" @click="state_type=0">全部</button>
                    <button :class="{active:state_type==1}" @click="state_type=1">
                        <img src="{{URL::asset('./img/icon/order_1.png')}}">
                        待付款
                    </button>
                    <button :class="{active:state_type==2}" @click="state_type=2">
                        <img src="{{URL::asset('./img/icon/order_2.png')}}">
                        待发货
                    </button>
                    <button :class="{active:state_type==3}" @click="state_type=3">
                        <img src="{{URL::asset('./img/icon/order_3.png')}}">
                        待收货
                    </button>
                    <button :class="{active:state_type==4}" @click="state_type=4">
                        <img src="{{URL::asset('./img/icon/order_4.png')}}">
                        待评价
                    </button>
                </div>
                <div class="orderMain_thead">
                    <span class="table_1">
                        订单详情
                    </span>
                    <span class="table_2">
                        金额
                    </span>
                    <span class="table_3">
                        交易状态
                    </span>
                    <span class="table_4">
                        操作
                    </span>
                </div>
                <div class="orderMain_tbody" v-for="items in listData">
                    <div class="tbody_thead">
                        <span>
                            <p>订单号：@{{items.order_sn}}</p>
                            <p>下单时间：@{{items.created_at}}</p>
                            <p>@{{items.store_name}}</p>
                        </span>
                        <span style="cursor: pointer;" v-if="items.is_delete==1" @click="changeState(items.id,3)">
                            <img src="{{URL::asset('./img/icon/order_8.png')}}">
                            删除
                        </span>
                    </div>
                    <div class="tbody_tbody" v-for="item in items.goods_list">
                        <span class="table_1">
                            <img :src="item.goods_image">
                            <span><a :href="'{{route('home.goods.goodsList') }}?goodsId='+item.id+'&type='+item.goods_type">
                                    @{{item.goods_name}}</a>
                            </span>
                            <span>￥@{{item.goods_price}}</span>
                            <span>1</span>
                        </span>
                        <span class="table_2">
                            <p>￥@{{item.goods_pay_price}}</p>
                            <p>@{{items.pay_method==1?'微信支付':'支付宝支付'}}</p>
                        </span>
                        <span class="table_3">
                            <p>@{{items.order_state==1?'已取消':items.order_state==2?'未付款':items.order_state==3?'已付款':items.order_state==4?'已发货':'已收货'}}</p>
                            <p v-if="items.is_logistics==1" @click="showWuliu(items.shipping_code,items.shipping_sn)">查看物流编号</p>
                        </span>
                        <span class="table_4">
                            <button v-if="items.order_state==2 && items.is_pay==1" style="margin-bottom:10px;">
                                付款
                            </button>
                            <button v-if="items.order_state==2 && items.is_cancel==1" @click="changeState(items.id,1)">
                                <img src="{{URL::asset('./img/icon/order_5.png')}}">
                                取消订单
                            </button>
                            <button v-if="items.order_state==4" @click="changeState(items.id,2)">
                                <img src="{{URL::asset('./img/icon/order_6.png')}}">
                                确认收货
                            </button>
                            <button v-if="items.order_state==5 && items.is_evaluation==1" @click=" window.location.href = '{{ route('home.goods.goodsDetails') }}?goodsId='+item.id+'&type='+item.goods_type">
                                <img src="{{URL::asset('./img/icon/order_7.png')}}">
                                评&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价
                            </button>
                        </span>
                    </div>
                </div>
            </div>
            <el-dialog :visible.sync="dialogVisible" width="400px" :before-close="handleClose">
                <div class="basicInfo_title">
                    <span></span>
                    订单管理中心
                    <a class="dialogFalse" @click="dialogVisible=false">×</a>
                </div>
                <div class="dialogMain">
                    <p>物流公司：@{{copyCode}}</p>
                    <p>物流单号：@{{copyText}}
                        <button class="copyBtn" :data-clipboard-text="copyText">复制</button>
                    </p>
                </div>
            </el-dialog>
            <div class="elementPage" style="margin-top: 20px;" v-if="pageCount>0">
                <el-pagination :pager-count="5" @current-change="handleCurrentChange" :current-page.sync="pageNumber" background prev-text="上一页" next-text="下一页" layout="prev, pager, next,jumper" :total="pageCount">
                </el-pagination>
            </div>

        </div>
    </div>

</div>
@endsection
@section('compontentScipts')
<script>
    $(() => {
        let hrOrder = new Vue({
            el: '#hrOrders',
            data: () => {
                return {
                    pageNumber: 1,
                    pageCount: 0,
                    listData: [],
                    state_type: 0,
                    dialogVisible: false,
                    status: 3,
                    copyCode: '',
                    copyText: ''
                }
            },
            watch: {
                state_type(newV) {
                    console.log(newV);
                    this.getList();
                }
            },
            created() {
                this.getList();
            },
            mounted() {
                let clipboard = new ClipboardJS('.copyBtn');
                clipboard.on('success', (e) => {
                    // console.info('Text:', e.text);
                    this.$message({
                        message: '复制成功',
                        type: 'success'
                    });
                    this.dialogVisible = false;
                    e.clearSelection();
                });

                clipboard.on('error', (e) => {
                    this.$message.error('复制失败');
                });
            },
            methods: {
                getList() {
                    let data = {
                        page: this.pageNumber,
                        state_type: this.state_type
                    }
                    apiAjax("{{ route('home.user.hrOrderListApi')}}", 'get', data, (res) => {
                        if (res.code == 0) {
                            this.pageCount = res.data.total;
                            this.listData = res.data.data;
                        } else {
                            this.$message({
                                message: res.msg,
                                type: 'warning'
                            });
                        }
                    }, (erro) => {

                    });
                },
                showWuliu(code, sn) {
                    this.copyCode = code;
                    this.copyText = sn;
                    this.dialogVisible = true;
                },
                handleCurrentChange(val) {
                    this.pageNumber = val;
                    this.getList();
                },
                handleClose(done) {
                    this.dialogVisible = false;
                },
                changeState(id, state) {
                    let data = {
                        order_id: id,
                        state_type: state,
                    }
                    apiAjax("{{ route('home.user.hrOrderChangeStateApi')}}", 'post', data, (res) => {
                        if (res.code == 0) {
                            this.$message({
                                message: res.msg,
                                type: 'success'
                            });
                            this.getList();
                        } else {
                            this.$message({
                                message: res.msg,
                                type: 'warning'
                            });
                        }
                    }, (erro) => {

                    });
                }
            }
        })
    })
</script>
@endsection